<template>
  <el-table
    :data="msglist"
    style="width: 100%">
    <el-table-column
      label="日期"
      style="width:10%">
      <template slot-scope="scope">
        <i class="el-icon-time"></i>
        <span style="margin-left: 10px">{{ scope.row.createTime | filterMoment }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="消息"
      style="width:80%">
      <template slot-scope="scope">
        <el-popover trigger="hover" placement="top">
          <p>{{ scope.row.itemDesc }}</p>
          <p></p>
          <div slot="reference" class="name-wrapper">
            <el-badge is-dot class="item" :hidden="scope.row.isread">
              <el-tag size="medium">{{ scope.row.itemDesc.length >25 ?scope.row.itemDesc.substr(0,15)+'....':scope.row.itemDesc }}</el-tag>
            </el-badge>
          </div>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="操作" style="width:10%">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">删除</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)" :disabled="scope.row.isread">{{scope.row.isread===true ? '已读' :'点击已读'}}</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import { getToken } from '_utils/auth.js'
import { mapGetters } from 'vuex'
export default {
  computed: {
    ...mapGetters([
      'msglist'
    ])
  },
  created () {
    this.getMsg()
  },
  methods: {

    handleEdit (index, row) {
      console.log(index, row)
      this.$store.commit('msg/DEL_MSG', index)
    },
    handleDelete (index) {
      this.$store.commit('msg/CHANGE_SATE', index)
    },
    getMsg () {
      this.$store.dispatch('msg/getMsg', getToken)
    }
  }
}
</script>
<style lang="scss" scoped>
.item {
  margin-top: 10px;
  margin-right: 40px;
}
</style>
